<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/1/21 0021
 * Time: 上午 11:52
 */
namespace app\admin\controller;

use think\Request;

class Express extends Base{
    public function index(){
        return parent::index();
    }

    public function handle(Request $request){
        $param = $request->param();
        if(empty($param['id']) || empty($param['status'])){
            return $this->error('缺少参数');
        }
        if($param['status'] ==1 || $param['status'] == 2){
            \app\admin\model\Express::where('id',$param['id'])->update(['status'=>$param['status']]);
            return $this->success('操作成功');
        }else{
            return $this->error('参数不合法');
        }

    }

    public function savepost(Request $request){
        if($request->isPost()){
            $param = $request->param();
            if(empty($param['name']) || empty($param['code'])){
                return $this->error('参数错误');
            }
            if(!empty($param['id'])){
                //修改
                \app\admin\model\Express::where('id',$param['id'])->update(['name'=>$param['name'],'code'=>$param['code']]);
            }else{
                //新增
                $model = new \app\admin\model\Express();
                $model->name = $param['name'];
                $model->code = $param['code'];
                $model->save();
            }
            return $this->success('操作成功');

        }else{
            return $this->error('非法请求');
        }

    }
}